package com.cx.bank.servlet;

import com.cx.bank.handler.MyInVocationHandler;
import com.cx.bank.manager.IManager;
import com.cx.bank.manager.ManagerImpl;
import com.cx.bank.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

/**
 * 刷新余额
 * @author jxau_scf
 * @date 2021/8/9 - 10:06
 */
@WebServlet(urlPatterns = "/user/refreshMoney")
public class RefreshMoneyServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String userId = req.getParameter("userId");
        //获取代理对象，方便使用日志
        IManager manager = new ManagerImpl();
        User user = null;
        try {
            user = manager.findUserByUserId(Integer.valueOf(userId));
        } catch (SQLException e) {
            e.printStackTrace();
        }
        System.out.println("refreshMoney=============>"+user);
        PrintWriter writer = resp.getWriter();
//        它将balance数据返回了前端，这里大部分时候也使用JSON
        writer.println(user.getBalance());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doGet(req,resp);
    }
}
